<?php

namespace admin\controllers;

use app\models\AdminMenu;
use admin\components\BaseAuthController;

class MenuController extends BaseAuthController {

    public $name = '菜单管理';
    public $defaultOrder = ['sort' => SORT_ASC, 'id' => SORT_DESC];
    public $sortAttributes = ['id', 'sort'];

    public function actionIndex() {
        $searchModel = !$this->enableSearch ? NULL : new AdminMenu();
        $query = AdminMenu::find();

        $dataProvider = $this->search($query, $searchModel);
        return $this->render("/index/{$this->id}", compact('searchModel', 'dataProvider'));
    }


    public function actionSave($id = FALSE) {
        /* @var $model AdminMenu */
        $model = $this->findModel($id, AdminMenu::className());
        if (!$model->load($this->post())) {
            return $this->render("/save/{$this->id}", compact('model'));
        }
        return $model->save();
    }

}
